//
//  InsTestViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2017/12/11.
//  Copyright © 2017年 史宵宵. All rights reserved.
//

#import "InsTestViewController.h"
#import "InstestIntroduceViewController.h"

@interface InsTestViewController ()
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation InsTestViewController
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"趣味测试题";
    [self creatDataList];
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
}
- (void)creatDataList{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppInterestGetInterestTopicList] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            [self.dataArray addObjectsFromArray: [NSMutableArray arrayWithArray:response[@"list"]]];
           
            MyLog(@"%@",self.dataArray);
            [self.tableView reloadData];
        }
    }];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1
                                      reuseIdentifier: CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        
//        UILabel *titleLabel = [[UILabel alloc]init];
//        titleLabel.tag = 1000;
//        titleLabel.textColor = KTEXTMAINCOLOR;
//        titleLabel.font = [UIFont systemFontOfSize:14];
//        titleLabel.textAlignment = NSTextAlignmentLeft;
//        [cell.contentView addSubview:titleLabel];
    }
//    UILabel *titleLabel = [cell.contentView viewWithTag:1000];
//    titleLabel.frame = CGRectMake(20, 12, kScreenW - 40, 20);
//    titleLabel.text = @"初中数学";
    
    cell.textLabel.text = strIsEmpty(self.dataArray[indexPath.row][@"name"])?@"":self.dataArray[indexPath.row][@"name"] ;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WebViewController *webVC = [[WebViewController alloc]initWithTitle:strIsEmpty(self.dataArray[indexPath.row][@"name"])?@"":self.dataArray[indexPath.row][@"name"] withRequest:self.dataArray[indexPath.row][@"url"]];
    [self.navigationController pushViewController:webVC animated:YES];
//    InstestIntroduceViewController *instestIntroduceVC = [[InstestIntroduceViewController alloc]init];
//    [self.navigationController pushViewController:instestIntroduceVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
